// pages/userInfo/userInfo.js
import ajax from '../network/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userId: "",
    data: {
      name: "",
      age: "",
      telNumber: "",
      entryTime: "",
      exigenceName: "", //紧急联系人
      exigenceTel: "", //紧急联系人
      bondsman: "", //担保人
      bondsmanTel: "",
      bondsmanBackground: "",
      identityProveSrc: "",
      identityBackSrc: "",
      backProve: "",
      backCardName: "",
      backCardNumber: '',
      idCardAddress: "",
      idCardName: "",
      idCardNumber: "",
      position: "",
      sex: "",
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  toUpdateInfo() {
    wx.navigateTo({
      url: '/pages/signIn/index?isupdate=1',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onLoad: function () {

  },
  onShow() {
    let userId = wx.getStorageSync('userId')
    if (userId) {
      this.setData({
        userId
      })
      ajax({
        url: "/api/user/userDetail",
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        data: {
          userId
        }
      }).then(result => {
        let v = result.data
        let _this = this
        this.setData({
          'data.age': v.age,
          'data.telNumber': v.tel,
          'data.entryTime': v.entryTime,
          'data.exigenceName': v.emergencyContactName, //紧急联系人
          'data.exigenceTel': v.emergencyContactTel, //紧急联系人
          'data.bondsman': v.guaranteeContactName, //担保人
          'data.bondsmanTel': v.guaranteeContactTel,
          'data.bondsmanBackground': v.diploma,
          'data.identityProveSrc': v.idCardFront,
          'data.identityBackSrc': v.idCardBack,
          'data.backProve': v.backCardImage,
          "data.backCardName": v.backCardName,
          "data.backCardNumber": v.backCardNumber,
          "data.idCardAddress": v.idCardAddress,
          "data.idCardName": v.idCardName,
          "data.idCardNumber": v.idCardNumber,
          "data.position": v.position,
          'data.sex': v.sex,
          "data.name": v.name
        })
      })
    } else {
      wx.showToast({
        icon: "none",
        title: '登录信息过期,重新登录',
        success: () => {
          wx.reLaunch({
            url: '/pages/login/index',
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})